﻿<UserControl x:Class="PAM.Core.TreeViewer"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:Core="clr-namespace:PAM.Core" xmlns:Converters="clr-namespace:PAM.Core.Converters" mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.Resources>
        <Converters:WidthConverter x:Key="WidthConverter" />
        <Core:TimeConverter x:Key="TimeConverter" />
        <Converters:InnerTextVisibilityConverter x:Key="InnerTextVisibilityConverter" />
        <Converters:OuterTextVisibilityConverter x:Key="OuterTextVisibilityConverter" />
    </UserControl.Resources>
    <Grid>
        <Grid.Resources>
                <HierarchicalDataTemplate x:Key="ChildTemplate" >
                    <StackPanel Orientation="Horizontal">
                        <Image Source="{Binding Path=Icon}" Margin="0,0,5,0" />
                        <TextBlock FontStyle="Italic" Text="{Binding Path=Name}" />
                    </StackPanel>
                </HierarchicalDataTemplate>
                <HierarchicalDataTemplate x:Key="ApplicationTemplate" ItemsSource="{Binding Path=Details}" ItemTemplate="{StaticResource ChildTemplate}">
                <DockPanel Margin="0,5,0,5">
                    <!--<StackPanel Orientation="Horizontal" Margin="0,5,0,5">-->
                    	<Image Source="{Binding Path=Icon}" Margin="0,0,5,0" />
                        <TextBlock Text="{Binding Path=Name}" VerticalAlignment="Center" Width="180"/>
                    <Border Name="ItemBar" Width="{Binding Path=TotalUsageTime, Converter={StaticResource WidthConverter}}" CornerRadius="5" Height="20px" Margin="5" VerticalAlignment="Center" HorizontalAlignment="Left">
                            <Label Content="{Binding Path=TotalUsageTime, Converter={StaticResource TimeConverter}}"  HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="11" Margin="0" Padding="0" Visibility="{Binding Path=TotalUsageTime, Converter={StaticResource InnerTextVisibilityConverter}}"  />
                            <Border.Background>
                                <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                                    <GradientStopCollection>
                                        <GradientStop Color="#2D00A500" Offset="0" />
                                        <GradientStop Color="#5B00A500" Offset="1" />
                                    </GradientStopCollection>
                                </LinearGradientBrush>
                            </Border.Background>
                        </Border>
                        <Label Content="{Binding Path=TotalUsageTime, Converter={StaticResource TimeConverter}}"  HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="11" Margin="0" Padding="0" Visibility="{Binding Path=TotalUsageTime, Converter={StaticResource OuterTextVisibilityConverter}}"  />
                    <!--</StackPanel>-->
                </DockPanel>
            </HierarchicalDataTemplate>
        </Grid.Resources>
            <Border VerticalAlignment="Stretch" >

                <TreeView Name="tree" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" ItemTemplate="{StaticResource ApplicationTemplate}" SizeChanged="TreeSizeChanged" />

            </Border>
    </Grid>
</UserControl>
